import org.apache.commons.collections.CollectionUtils;
import java.util.List;
import java.util.Map;

public class QueryDatasApplication {

    public static void main(String[] args) {
        //**********这里获取jar执行命令中的参数**************
        //比如java -jar XXX.jar "sql"
        String sql = args[0];

        try {
            //查询hive
//            String sql = "select name,id_card from hbzfw.t_user";
            List<Map<String, Object>> result = HiveClientUtils.getResult(sql);
            if (CollectionUtils.isEmpty(result)){
                System.out.println("--------------query hive null");
                return;
            }

            //结果输出到hdfs
            ///data/result/2019/08/27/
            String resUri = "/data/result/"+HdfsFileSystem.getCurrentDatePath();

            String content = JacksonUtil.writeValueAsString(result);
            ///生成本地文件
            String filename = HdfsFileSystem.writeFile(content);
            //上传hdfs
            HdfsFileSystem.copyFileToHDFSByFileObj(filename,resUri);
            System.out.println("--------------send data to hdfs success");
            //删除本地文件
            HdfsFileSystem.deleteFile(filename);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }




}
